nhj = True
def isp(k):
    if k < 2:
        return False
    for i in range(2, int(k**0.5) + 1):
        if k % i == 0:
            return False
    return True

def nextp(k):
    while True:
        k += 1
        if isp(k):
            return k
            
def prevp(k):
    while True:
        k -= 1
        if isp(k):
            return k

w = input().split()
k_str = ""
for w in w:
    if w == "zero":
        k_str += "0"
    elif w == "one":
        k_str += "1"
    elif w == "two":
        k_str += "2"
    elif w == "three":
        k_str += "3"
    elif w == "four":
        k_str += "4"
    elif w == "five":
        k_str += "5"
    elif w == "six":
        k_str += "6"
    elif w == "seven":
        k_str += "7"
    elif w == "eight":
        k_str += "8"
    elif w == "nine":
        k_str += "9"
    if w == '1' or w == '2' or w == '3' or w == '4' or w == '5' or w == '6' or w == '7' or w == '8' or w == '9':
        print('Wrong input')
        nhj == False
if nhj == True:
    k = int(k_str)
    nextp_num = nextp(k)
    prevp_num = prevp(k)
    if (nextp_num - k) >= (k - prevp_num):
        print(prevp_num)
    elif (nextp_num - k) < (k - prevp_num):
        print(nextp_num)
